Thread: Error: no `int ClMath::colorRegulator(int, int)' member function declared in class

  1. #1
    Registered User
    Join Date
    Mar 2008
    Posts
    71

    Error: no `int ClMath::colorRegulator(int, int)' member function declared in class

    Hey all,

    I've searched on the internet, a found about 4 sites/forums where people had the same problem, except none of the solutions that were listed worked for me. I really don't know what's wrong, so either my compiler is acting up or I'm missing something so obvious that I don't even realize it. Here's the code:

    Code:
    //ClassMath.h
    
    #ifndef CLASS_MATH_H
        #define CLASS_MATH_H
    
    #include <cmath>
    #include <cstdlib>
    #include "ClassRange.h"
    
    using namespace std;
    
    class ClMath {
        public:
    
        static long double dPI;
    
        //Rounds value up or down
        static long int round(long double dNum);
    
        //Returns random value in range
        static long int randNum(ClRange<long int> rnRange);
    
        static int colorRegulator(int x, int r);
    };
    
    #endif
    Code:
    //ClassMath.cpp
    
    #include "ClassMath.h"
    
    using namespace std;
    
    long double ClMath::dPI = 4 * atan(1);
    
    long int ClMath::randNum(ClRange<long int> rnRange)
    {
        if((rnRange.getUpper() > RAND_MAX) && ((rnRange.getUpper() - rnRange.getLower()) > RAND_MAX)) {
    
            long int RandNum = rand();
            long int nNumRands = static_cast<long int>((rnRange.getUpper() - rnRange.getLower()) / RAND_MAX);
    
            RandNum += (rand() % nNumRands ) * RAND_MAX;
    
            if ((rnRange.getUpper() - rnRange.getLower()) != RAND_MAX * nNumRands)
                RandNum += rand() % ((rnRange.getUpper() - rnRange.getLower()) - (RAND_MAX * nNumRands) + 1);
    
            return RandNum + rnRange.getLower();
        }
    
        else
            return rand() % (rnRange.getUpper() - rnRange.getLower() + 1 ) + rnRange.getLower();
    }
    
    long int ClMath::round(long double dNum)
    {
        if (static_cast<long int>(ceil(dNum + 0.5)) > static_cast<long int>(ceil(dNum)))
            return static_cast<int>(ceil(dNum));
        else
            return static_cast<int>(floor(dNum));
    }
    
    int ClMath::colorRegulator(int x, int r)
    {
        return static_cast<int>((pow(pow(255.0, x) * x / r, 1/x)));
    }
    And the error is C:\...\ClassMath.cpp|35|error: no `int ClMath::colorRegulator(int, int)' member function declared in class `ClMath'.

    I'm using CodeBlocks with MinGW, and I've never had any problems before, so I hope this isn't the first.

    Cheers,

    Gabe

  2. #2
    The larch
    Join Date
    May 2006
    Posts
    3,573
    Is this the only error and the first error?
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  3. #3
    Registered User
    Join Date
    Mar 2008
    Posts
    71
    Yup. The program works fine, I'm just tweaking it a bit so it'll look better, and once I add that function it won't compile.
    Last edited by G4B3; 05-02-2009 at 08:21 AM.

  4. #4
    The larch
    Join Date
    May 2006
    Posts
    3,573
    Perhaps you could also post "ClassRange.h" and the main function?

    I don't have any problems with that (as one file, but ordered to minimize dependancies. E.g ClMath doesn't need to include any headers.)

    Code:
    template <class T>
    class ClRange;
    
    class ClMath {
        public:
    
        static long double dPI;
    
        //Rounds value up or down
        static long int round(long double dNum);
    
        //Returns random value in range
        static long int randNum(const ClRange<long int>& rnRange);
    
        static int colorRegulator(int x, int r);
    };
    
    
    template <class T>
    class ClRange
    {
       T from, to;
    public:
        ClRange(T from, T to): from(from), to(to) {}
        T getLower() const { return from; }
        T getUpper() const { return to; }
    };
    
    #include <iostream>
    int main()
    {
        std::cout << ClMath::randNum(ClRange<long int>(0, 128)) << '\n';
        std::cout << ClMath::colorRegulator(34, 45) << '\n';
    }
    
    
    
    #include <cmath>
    
    using namespace std;
    
    long double ClMath::dPI = 4 * atan(1);
    
    long int ClMath::randNum(const ClRange<long int>& rnRange)
    {
        if((rnRange.getUpper() > RAND_MAX) && ((rnRange.getUpper() - rnRange.getLower()) > RAND_MAX)) {
    
            long int RandNum = rand();
            long int nNumRands = static_cast<long int>((rnRange.getUpper() - rnRange.getLower()) / RAND_MAX);
    
            RandNum += (rand() % nNumRands ) * RAND_MAX;
    
            if ((rnRange.getUpper() - rnRange.getLower()) != RAND_MAX * nNumRands)
                RandNum += rand() % ((rnRange.getUpper() - rnRange.getLower()) - (RAND_MAX * nNumRands) + 1);
    
            return RandNum + rnRange.getLower();
        }
    
        else
            return rand() % (rnRange.getUpper() - rnRange.getLower() + 1 ) + rnRange.getLower();
    }
    
    long int ClMath::round(long double dNum)
    {
        if (static_cast<long int>(ceil(dNum + 0.5)) > static_cast<long int>(ceil(dNum)))
            return static_cast<int>(ceil(dNum));
        else
            return static_cast<int>(floor(dNum));
    }
    
    int ClMath::colorRegulator(int x, int r)
    {
        return static_cast<int>((pow(pow(255.0, x) * x / r, 1/x)));
    }
    Last edited by anon; 05-02-2009 at 08:28 AM.
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  5. #5
    Registered User
    Join Date
    Mar 2008
    Posts
    71
    Sure, although I doubt that will help you much; main is a mess, I haven't cleaned it up yet, and ClassRange has been used in a couple of programs before without any problems

    Code:
    //ClassRange.h
    
    #ifndef CLASS_RANGE_H
        #define CLASS_RANGE_H
    
    using namespace std;
    
    template <typename T>
    class ClRange{
        private:
            T m_tLoBound;
            T m_tHiBound;
    
        public:
            ClRange(T tLoBound, T tHiBound)
                    :m_tLoBound(tLoBound), m_tHiBound(tHiBound)
                    {}
            ClRange()
                    :m_tLoBound(0), m_tHiBound(0)
                    {}
            ~ClRange() {}
    
            T getLower() { return m_tLoBound; }
            T getUpper() { return m_tHiBound; }
    
            void setLower(T tValue) { m_tLoBound = tValue; }
            void setUpper(T tValue) { m_tHiBound = tValue; }
            void set(T tLower, T tUpper) { m_tLoBound = tLower; m_tHiBound = tUpper; }
    };
    
    #endif
    Code:
    //main.cpp
    
    #include <cstdlib>
    #include <ctime>
    #include "ClassUniverse.h"
    #include "ClassValues.h"
    
    using namespace std;
    
    int main()
    {
        allegro_init();
    
        install_timer();
        install_keyboard();
    
        set_color_depth(32);
        if (set_gfx_mode(GFX_AUTODETECT_WINDOWED, ClValues::nScreenHight, ClValues::nScreenWidth, 0, 0) < 0) {
            allegro_message("Couldn't set gfx mode: %s\n", allegro_error);
            exit(1);
        }
    
        ClValues::dblbuffer = create_bitmap(ClValues::nScreenHight, ClValues::nScreenWidth);
        clear(ClValues::dblbuffer);
    
        srand(time(NULL));
    
        ClUniverse TheUniverse;
    
        while(!key[KEY_ESC]) {
            TheUniverse.calculateDisplacement();
            TheUniverse.drawObjects();
        }
    
        return 0;
    }
    END_OF_MAIN();
    Hope it helps.

  6. #6
    Registered User
    Join Date
    Mar 2008
    Posts
    71
    Well, when I include the definition in the class, as in

    Code:
    #ifndef CLASS_MATH_H
        #define CLASS_MATH_H
    
    #include <cmath>
    #include <cstdlib>
    #include "ClassRange.h"
    
    using namespace std;
    
    class ClMath {
        public:
    
        static long double dPI;
    
        //Rounds value up or down
        static long int round(long double dNum);
    
        //Returns random value in range
        static long int randNum(ClRange<long int> rnRange);
    
        static int colorReg(int x, int r) { return static_cast<int>((pow(pow(255.0, x) * x / r, 1/x))); }
    };
    
    #endif
    it works fine. So now I'm really lost.

  7. #7
    The larch
    Join Date
    May 2006
    Posts
    3,573
    Not really

    There doesn't seem anything technically wrong with these files, so perhaps you could try a full rebuild and see if any other headers introduce circular dependancies.

    All I can say is that I don't see why something with only static functions should be a class (global functions/variables, perhaps in a namespace to avoid collisions with other libraries would be just as good).

    You can also try reducing dependencies (see code above how header of ClMath can be made depend on no other headers) and get rid of the using namespace std; in headers (as you don't need anything from that anyway).
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  8. #8
    Registered User
    Join Date
    Mar 2008
    Posts
    71
    ClassMath is only dependent on <cmath>, <cstdlib> and "ClassRange.h". It needs the former two and while it doesn't need the last, I still don't see how that could be preventing a successful compilation, especially since the new function doesn't even use ClRange. As for why I'm making a class with only static functions, I guess it's personal preference. I started learning Java some time ago, and since then I prefer having everything enclosed in a class.

    EDIT: Oh, and I already tried completely re-building the whole thing; didn't help. Oh well, guess I'll have to live with the fact that one of the function definitions is going to have to be included with the declaration. Thanks for your help.

  9. #9
    The larch
    Join Date
    May 2006
    Posts
    3,573
    ClassMath is only dependent on <cmath>, <cstdlib> and "ClassRange.h"
    The declaration doesn't depend on <cmath> and <cstdlib>, and the dependancy on "ClassRange.h" can be removed with a forward declaration. It is the implementation that depends on them, which means they can be included in the cpp file.

    If you don't mind, you could attach all the files, so it would be possible to take a look.
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  10. #10
    Registered User
    Join Date
    Mar 2008
    Posts
    71
    Oh...well, again because of personal preference, I decided to include all the files in the headers, since the .cpp files include the headers plus everything the headers include. Didn't know it could cause problems.

    The next part is just short of being hilarious (if it weren't so serious of course ). I was uploading the files as you requested, and by chance noticed there was a ClassMath.h.gch file in the folder. So I went and removed that, and bingo, the program works. So, thank you for your help AND for your request I guess

    On a more serious note, anyone know what that file is? I still have it here, so I can upload it if anyone wants to have a look... a search on Google returned "(a .gch is basically a dump of the internal memory state of GCC, which can differ with each version)."...any idea on how that could have affected the program?

  11. #11
    The larch
    Join Date
    May 2006
    Posts
    3,573
    It looks like you are (perhaps unknowningly) using precompiled headers. I haven't used them myself.
    I might be wrong.

    Thank you, anon. You sure know how to recognize different types of trees from quite a long way away.
    Quoted more than 1000 times (I hope).

  12. #12
    Registered User
    Join Date
    Mar 2008
    Posts
    71
    I guess this goes hand in hand with a problem I had when I first compiled the program, when for some reason ClassMath.h had "compile file" and "link file" checked in its properties. Anyway, I fixed that, but missed this...I had a feeling that it was somehow going to be linked to this problem, but I didn't see how so I didn't even mention it. Probably should have.

    Thanks again

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Code review
    By Elysia in forum C++ Programming
    Replies: 71
    Last Post: 05-13-2008, 09:42 PM
  2. Please Help - Problem with Compilers
    By toonlover in forum C++ Programming
    Replies: 5
    Last Post: 07-23-2005, 10:03 AM
  3. structure vs class
    By sana in forum C++ Programming
    Replies: 13
    Last Post: 12-02-2002, 07:18 AM
  4. qt help
    By Unregistered in forum Linux Programming
    Replies: 1
    Last Post: 04-20-2002, 09:51 AM
  5. easy if you know how to use functions...
    By Unregistered in forum C Programming
    Replies: 7
    Last Post: 01-31-2002, 07:34 AM